<template>
	<div class="boxStyle">
		<el-row type="flex" class="row-bg" justify="start" style="margin-bottom: 10px;">
			<el-col :span="1" style="margin-top: 5px;padding-left: 10px;width: 80px;">订单号:</el-col>
			<el-col :span="2">
				<el-input v-model="orderId" placeholder="请输入订单号" size="small"></el-input>
			</el-col>
			<el-col :span="1" style="margin-top: 5px;padding-left: 10px;">推广人:</el-col>
			<el-col :span="3" style="margin-right: 10px;">
				<el-input v-model="queryparms" placeholder="请输入推广人" size="small"></el-input>
			</el-col>
			<el-col :span="1" style="margin-top: 5px;padding-left: 10px;width: 80px;">状态:</el-col>
			<el-col :span="2">
				<el-select v-model="status" placeholder="请选择" size="small" style="width: 100px;">
					<el-option label="全部" value=""></el-option>
					<el-option key="0" label="待审核" value="0"></el-option>
					<el-option key="2" label="已通过" value="2"></el-option>
					<el-option key="1" label="已拒绝" value="1"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right: 10px;margin-left: 20px;">
				<el-button type="warning" icon="el-icon-search" size="small" @click="search">查找</el-button>
			</el-col>

		</el-row>
		<el-row type="flex" class="row-bg" justify="start" style="margin-bottom: 10px;">
			<el-col :span="2" style="margin-right: 0px;">
				<el-button type="warning" size="small" @click="deal(2)" v-if="dealShow!==-1">批量通过</el-button>
			</el-col>
			<el-col :span="2" style="margin-right: 10px;">
				<el-button type="warning" size="small" @click="deal(1)" v-if="dealShow!==-1">批量拒绝</el-button>
			</el-col>
		</el-row>
		<el-table :data="tableData" border style="width:100%" @selection-change="handleSelectionChange">
			<el-tableref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column prop="orderId" label="订单号" width="220"></el-table-column>
				<el-table-column prop="nickName" label="推广账号" width="100"></el-table-column>
				<el-table-column prop="name" label="姓名" width="110"></el-table-column>
				<el-table-column prop="mobile" label="手机号" width="110"></el-table-column>
				<el-table-column prop="orderPrice" label="订单金额" width="100"></el-table-column>
				<el-table-column prop="commissionPrice" label="佣金" width="80"></el-table-column>
				<el-table-column label="状态" width="100">
					<template slot-scope="scope">
						<label v-if="scope.row.status==0">待审核</label>
						<label v-if="scope.row.status==2">已通过</label>
						<label v-if="scope.row.status==1">已拒绝</label>
					</template>
				</el-table-column>
				<el-table-column prop="createTime" label="付款时间" width="180" :formatter="dateFormat"></el-table-column>
				<el-table-column label="操作" min-width="100">
					<template slot-scope="scope">
						<el-button v-if="scope.row.status==0&&dealShow!==-1" size="mini" type="danger" @click="updata(scope.row.id,1)">拒绝</el-button>
						<el-button v-if="scope.row.status==0&&dealShow!==-1" style="margin-left: 0px;margin-top: 5px;" size="mini" type="danger" @click="updata(scope.row.id,2)">通过</el-button>
					</template>
				</el-table-column>
		</el-table>
		<el-pagination background @current-change="handleCurrentChange" :current-page="Page" :page-size="size" layout="prev, pager, next,total, slot" :total="totals">
			<span style="margin-top: -2px;color: #606266;font-weight: 100;">第<el-input type="text" v-model="inputPage" style="width: 60px;margin: 0 5px;"/>页<el-button size="mini" style="background: #409EFF; color: #fff;margin:0 5px;" @click="handleCurrentChange(inputPage)">跳转</el-button><span>总计{{totalPage}}页</span></span>
		</el-pagination>
	</div>
</template>

<script>
	import { formatDate } from 'static/js/date.js'
	import qs from "qs"
	import axios from "axios"
	export default {
		data() {
			return {
				Page: 1, //当前页
				inputPage: 1,
				totals: 0, //分页总条数
				totalPage: 0,
				size: 0, //每页条数
				purl: this.$store.state.purl, //权限数组
				orderId: "", //搜索订单号
				queryparms: "", //搜索推广人
				status: "",
				tableData: [],
				multipleSelection: "",
				dealShow:0,
			}
		},
		activated() {
			this.Page = 1
			this.totals = 0
			this.size = 0
			this.inputPage = 1
			this.totalPage = 1
			this.purl = this.$store.state.purl
			this.orderId=""; //搜索订单号
			this.queryparms="";//搜索推广人
			this.status= "";
			this.tableData= [];
			this.multipleSelection= "";
			this.load(1);
			this.dealShow = this.purl[0].findIndex((val) => val === "/interface/shopaudit/status")
		},
		mounted() {
			this.load(1);
			//			this.addShow = this.purl[0].findIndex((val) => val === "/interface/dictionary/create") //判断是否拥有增加权限
			//			console.log(this.addShow)
		},
		methods: {
			load(num) {
				axios.get("/interface/shopaudit/list?pageNo=" + num).then((res) => {
					this.tableData = res.data.data.list; //list数据
						this.totals = res.data.data.pageBean.totalRow; //总条数
						this.size = res.data.data.pageBean.pageSize; //每页条数 
						this.totalPage = res.data.data.pageBean.totalPage; //总页数
					/*this.logOptions=res.data.data.logistics;*/
				})
			},
			dateFormat: function(row, column) {
				var date
				if(row[column.property]) {
					date = new Date(parseInt(row[column.property]))
					date = formatDate(date, 'yyyy-MM-dd hh:mm:ss')
				}
				if(date == undefined) {
					return "";
				}
				return date;
			},
			handleCurrentChange(val) {
				var thit = this;
				thit.inputPage=val;
				thit.Page = val;
				axios.post("/interface/shopaudit/list?", qs.stringify({
					orderId: thit.orderId,
					nickName: thit.queryparms,
					status: thit.status,
					pageNo: val
				})).then((res) => {
					this.tableData = res.data.data.list; //list数据
						this.totals = res.data.data.pageBean.totalRow; //总条数
						this.size = res.data.data.pageBean.pageSize; //每页条数 
						this.totalPage = res.data.data.pageBean.totalPage; //总页数
				})
			},
			search() {
				var thit = this;
				thit.inputPage=1;
				thit.Page =1;
				axios.post("/interface/shopaudit/list?", qs.stringify({
					orderId: thit.orderId,
					nickName: thit.queryparms,
					status: thit.status,
					pageNo: 1
				})).then((res) => {
					this.tableData = res.data.data.list; //list数据
						this.totals = res.data.data.pageBean.totalRow; //总条数
						this.size = res.data.data.pageBean.pageSize; //每页条数 
						this.totalPage = res.data.data.pageBean.totalPage; //总页数
				})
			},
			updata(id, sta) {
				axios.post("/interface/shopaudit/status?", qs.stringify({
					ids: id,
					status: sta
				})).then((res) => {
					var msg = res.data;
					if(msg.code == 1) {
						if(sta==2){
							this.$message({message: '审核通过成功',type: 'success'});
						}else{
							this.$message({message: '审核拒绝成功',type: 'success'});
						}
						this.load(1);
					} else {
						this.$notify.error({
							title: '错误',
							message: msg.msg
						});
					}
				})
			},
			handleSelectionChange(val) {
				var strId = "";
				
				for(var i = 0; i < val.length; i++) {
					if(val[i].status == 0) {
						strId += val[i].id + ",";
					}
				}
				strId = strId.slice(0, strId.length - 1);
				this.multipleSelection = strId;
			},
			deal(stu) {
				if(this.multipleSelection == "" || this.multipleSelection== null) {
					this.$notify.error({
						title: '错误',
						message: "暂无可待审核数据"
					});
					return
				}
				var ids = this.multipleSelection;
				axios.post("/interface/shopaudit/status?", qs.stringify({
					ids: ids,
					status: stu
				})).then((res) => {
					var msg = res.data;
					if(msg.code == 1) {
						if(stu==2){
							this.$message({message: '审核通过成功',type: 'success'});
						}else{
							this.$message({message: '审核拒绝成功',type: 'success'});
						}
						this.load(1);
					} else {
						this.$notify.error({
							title: '错误',
							message: msg.msg
						});
					}
				})
			},
		}
	}
</script>

<style>

</style>